/**
 * Copyright (C) 2025 ROKAE (Beijing) Technology Co., LTD.
 * All Rights Reserved.
 *
 * Information in this file is the intellectual property of Rokae Technology Co., Ltd,
 * And may contains trade secrets that must be stored and viewed confidentially.
 *
 * @file ElectricClawPlugin.h
 * @brief 初始化 UI 界面，并注册 RL 指令
 */
#include "ElectricClawPlugin.h"

XPLUGIN_REGISTER(PLUGIN_NAME, ElectricClawPlugin)

xplugin::ElectricClawPlugin::ElectricClawPlugin(QObject *parent)
    :xplugin::PluginBase(parent)
{}

void xplugin::ElectricClawPlugin::init()
{
    // 创建插件主界面控件 ElectricClawWidget，并注册为中心控件
    m_widget = new ElectricClawWidget;
    xplugin::CreateCenterWidget(PLUGIN_NAME, m_widget);
}

void xplugin::ElectricClawPlugin::afterInit()
{
    // 创建 RLManager，用于注册流程控制脚本中可用的 RL 指令
    m_rlManager = new xplugin::RLManager(this);

    // ----- 注册 ElectricClawStart 指令 -----
    m_rlManager->createTypeKey("ElectricClawStart");
    m_rlManager->createSkeleton("ElectricClawStart", "ElectricClawStart");
    m_rlManager->createInsDescribe("ElectricClawStart", QString(tr("Start the electric claw")));    // 描述
    m_rlManager->createPattern("ElectricClawStart", QString("^\\s*%1\\s*(?://.*)?$").arg("ElectricClawStart")); // 匹配正则
    m_rlManager->createInsertWidget("ElectricClawStart", [](){
        return new xplugin::RLStartWidget("ElectricClawStart"); // 插入时使用的控件
    });

    // ----- 注册 ElectricClawStop 指令 -----
    m_rlManager->createTypeKey("ElectricClawStop");
    m_rlManager->createSkeleton("ElectricClawStop", "ElectricClawStop");
    m_rlManager->createInsDescribe("ElectricClawStop", QString(tr("Stop the electric claw")));
    m_rlManager->createPattern("ElectricClawStop", QString("^\\s*%1\\s*(?://.*)?$").arg("ElectricClawStop"));
    m_rlManager->createInsertWidget("ElectricClawStop", [](){
        return new xplugin::RLStopWidget("ElectricClawStop");
    });

    // ----- 注册 ElectricClawStatus 指令 -----
    m_rlManager->createTypeKey("ElectricClawStatus");
    m_rlManager->createSkeleton("ElectricClawStatus", "ElectricClawStatus");
    m_rlManager->createInsDescribe("ElectricClawStatus", QString(tr("Get the electric claw status")));
    m_rlManager->createPattern("ElectricClawStatus", QString("^\\s*%1\\s*(?://.*)?$").arg("ElectricClawStatus"));
    m_rlManager->createInsertWidget("ElectricClawStatus", [](){
        return new xplugin::RLStatusWidget("ElectricClawStatus");
    });


    // 指令分组
    m_rlManager->createTypeToGroup("ElectricClawPlugin", QStringList() << "ElectricClawStart" << "ElectricClawStop" << "ElectricClawStatus");

    // 创建分组界面标题
    m_rlManager->createGroups(tr("ElectricClaw Group"), "ElectricClawPlugin");
}

